package codingforgreat.lchot150;

public class Lc034 {
    public int[] searchRange(int[] nums, int target) {
        if (nums == null || nums.length == 0) {
            return new int[] { -1, -1 };
        }
        int L = findLeft(nums,target);//<target 最左边
        if(L + 1 < nums.length && nums[L + 1] == target){
            return new int[]{L + 1,findLeft(nums,target + 1)};
        }else{
            return new int[]{-1,-1};
        }
    }
    public int findLeft(int[] nums,int target){
        int L = 0;
        int R = nums.length - 1;
        int ans = -1;
        while(L <= R){
            int mid = (L + R)/2;
            if(nums[mid] >= target){
                R = mid - 1;
            }else{//<
                ans = mid;
                L = mid + 1;
            }
        }
        return ans;
    }
}
